/*
Copyright SecureKey Technologies Inc. All Rights Reserved.

SPDX-License-Identifier: Apache-2.0
*/
package iam

import (
	"git.cloud.inspur.com/ichain/ichain-sdk-go/pkg/providers/core"
	"github.com/pkg/errors"
)

var (
	ErrUserNotFound = errors.New("user not found")
)

// IdentityOption 创建身份的选择项
type IdentityOption struct {
	Cert       []byte
	PrivateKey []byte
}

type SigningIdentityOption func(*IdentityOption) error

// WithPrivateKey 传入密钥
func WithPrivateKey(key []byte) SigningIdentityOption {
	return func(o *IdentityOption) error {
		o.PrivateKey = key
		return nil
	}
}

// WithCert 传入证书
func WithCert(cert []byte) SigningIdentityOption {
	return func(o *IdentityOption) error {
		o.Cert = cert
		return nil
	}
}

type IdentityManager interface {
	GetSigningIdentity(name string) (SigningIdentity, error)
	CreateSigningIdentity(ops ...SigningIdentityOption) (SigningIdentity, error)
}

type Identity interface {
	Identifier() *IdentityIdentifier

	Verify(msg []byte, sig []byte) error

	Serialize() ([]byte, error)

	EnrollmentCertificate() []byte
}

type SigningIdentity interface {
	Identity
	Sign(msg []byte) ([]byte, error)
	PublicVersion() Identity
	PrivateKey() core.Key
}

type IdentityIdentifier struct {
	IAMID string
	ID    string
}
